#include "stm32f10x.h"
#include "Speed_PID.h"
#include "PWM.h"

extern int16_t rpm;

uint16_t rpm_2_paulse_counts(int16_t rpm){

       
    return rpm/Motor_MAX_SPEED * AUTO_RELOAD_REGISTER_VALUE;
}

void set_rpm(int16_t expected_rpm,float dt){

    // 误差
    int16_t error = expected_rpm - rpm;

    static float last_error=0;
		float Kp=10,Ki=1,Kd =1;
    
    uint16_t output_rpm=0;
    

    
    output_rpm = Kp * error + (error-last_error)/dt;
    
    // 输出脉冲的数量
    uint16_t output_pulse_count =rpm_2_paulse_counts(output_rpm);
    
}
